import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:mirror/AppStyle.dart';
import 'package:mirror/page/TestPage.dart';
import 'package:mirror/service/CacheService.dart';
import 'package:mirror/service/NetworkService.dart';
import 'package:mirror/service/ProviderService.dart';
import 'package:provider/provider.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await NetworkService.setup(baseUrl: "http://mirror.ging.plus/");
  await CacheService.setup();
  runApp(
    ChangeNotifierProvider(
      create: (context) => ProviderData(),
      child: const MyApp(),
    ),
  );
}

final GlobalKey<NavigatorState> navigatorKey = GlobalKey();

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    var myData = Provider.of<ProviderData>(context);
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      navigatorKey: navigatorKey,
      theme: ThemeData(
          appBarTheme: AppBarTheme(color: Constant.mainColor),
          bottomNavigationBarTheme: const BottomNavigationBarThemeData(
              selectedItemColor: Colors.black,
              unselectedItemColor: Colors.grey)),
      home: const TestPage(),
      localizationsDelegates: const [
        GlobalMaterialLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
      ],
      supportedLocales: const [
        Locale('zh', 'CH'),
        Locale('en', 'US'),
      ],
      locale: const Locale('zh'),
    );
  }
}
